package com.qfhd.soft.cjzcore.UI.Custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qfhd.soft.cjzcore.Model.Task_image_item_model;
import com.qfhd.soft.cjzcore.R;
import com.qfhd.soft.cjzcore.UI.Listener.CJOnlistListener;
import com.qfhd.soft.cjzcore.UI.MulitRecycle.adapter.MulitAdpter;
import com.qfhd.soft.cjzcore.UI.MulitRecycle.bean.Task_image_Bean;
import com.qfhd.soft.cjzcore.UI.MulitRecycle.decorate.Visitable;

import java.util.ArrayList;
import java.util.List;

public class CJImgTask extends RelativeLayout {
    private Context mContext;
    private AttributeSet mAttr;

    private RecyclerView recyclerView;
    private MulitAdpter adpter;

    public CJImgTask(Context context) {
        this(context,null);
    }

    public CJImgTask(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CJImgTask(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs);
    }

    private void init(Context context,AttributeSet attr){
        mContext    = context;
        mAttr       = attr;

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView              = inflater.inflate(R.layout.img_task_layout,this,true);
        recyclerView            = mView.findViewById(R.id.imgTask_recycleV);

        adpter = new MulitAdpter();
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));
        recyclerView.getItemAnimator().setChangeDuration(0);
        recyclerView.setAdapter(adpter);
    }

    public boolean setData(List<Task_image_item_model> list,Context context){
        if(list.size() > 0) {
            List<Visitable> tmp = new ArrayList<>();
            for (Task_image_item_model model : list) {
                Task_image_Bean bean = new Task_image_Bean(model, context);
                tmp.add(bean);
            }
            adpter.setList(tmp);
            return true;
        }
        else{
            return false;
        }
    }

    public void setItemClickListener(CJOnlistListener listener){
        if(listener != null){
            adpter.setOnclickListener(listener);
        }
    }
}
